﻿using Rabbit.Domain.Entity;
using Rabbit.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Domain.Repository
{
    public class ButcherRepository : IButcherRepository
    {
        private readonly RbacContext _context;

        public ButcherRepository(RbacContext context)
        {
            _context = context;
        }

       

        /// <summary>
        /// 添加屠宰
        /// </summary>
        /// <param name="butcher"></param>
        /// <returns></returns>
        public int GetButcherAdd(Butcher butcher)
        {
            var list=_context.Butchers.Add(butcher);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic GetButcherFind(int id)
        {
            var list=_context.Butchers.FirstOrDefault(x=>x.ButcherId == id);
            return list;
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Butcher> GetButcherShow(int id)
        {
            var list=_context.Butchers.Where(x=>x.GoodInfoId==id).ToList();
            return list;
        }

        /// <summary>
        /// 修改屠宰
        /// </summary>
        /// <param name="butcher"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetButcherXiu(Butcher butcher)
        {
            var list=_context.Butchers.FirstOrDefault(x=>x.ButcherId==butcher.ButcherId);
            list.ButcherStime=butcher.ButcherStime;
             list.ButcherBatch=butcher.ButcherBatch;
             list.ButcherEtime=butcher.ButcherEtime;
             list.ButcherId=butcher.ButcherId;
             list.ButcherWeight=butcher.ButcherWeight;
             list.ButcherStime = butcher.ButcherStime;
             _context.Butchers.Update(list);
             return _context.SaveChanges();
            
        }

        /// <summary>
        /// 省
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<province> GetProvince()
        {
            return _context.provinces.ToList();
        }

        /// <summary>
        /// 市
        /// </summary>
        /// <param name="provinceid"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<city> GetCitie(int provinceid)
        {
            var list=_context.citys.Where(x=>x.ProvinceId==provinceid).ToList();
            return list;
        }

        /// <summary>
        /// 区
        /// </summary>
        /// <param name="cityid"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<area> GetArea(int cityid)
        {
            var list=_context.areas.Where(x=>x.CityId==cityid).ToList();
            return list;
        }

        /// <summary>
        /// 屠宰公司显示
        /// </summary>
        /// <returns></returns>
        public List<Tcompany> GetTcompanies()
        {
            var list=_context.Tcompanies.ToList();
            return list;
        }

        /// <summary>
        /// 屠宰公司反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic GetTcompanyFind(int id)
        {
            var list=_context.Tcompanies.Where(x=>x.TcompanyId==id).ToList();
            return list;
        }

        /// <summary>
        /// 屠宰公司修改
        /// </summary>
        /// <param name="tcompany"></param>
        /// <returns></returns>
        public int GetTcompanyXiu(Tcompany tcompany)
        {
            var list=_context.Tcompanies.Update(tcompany);
            return _context.SaveChanges();
        }
    }
}
